package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("/test")
public class TestController {
    private static Logger logger = LoggerFactory.getLogger(LoggerFactory.class);

    @Autowired
    private UserService userService;

    @RequestMapping("/filter")
    public void test1(HttpServletRequest request, HttpServletResponse response){

        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
        UserService userService = ctx.getBean(UserService.class);
        List<User> all = userService.findAll();
        System.out.println(all);

    }

    public void test2(){
        List<User> all = userService.findAll();

    }
}
